//主js，需要jquery~
var a1=0,imgdir="data/img/";
function craft(id)
{
var craftclass=id+" .a1";
cc(craftclass);
craftclass=id+" .a2";
cc(craftclass);
craftclass=id+" .a3";
cc(craftclass);
craftclass=id+" .b1";
cc(craftclass);
craftclass=id+" .b2";
cc(craftclass);
craftclass=id+" .b3";
cc(craftclass);
craftclass=id+" .c1";
cc(craftclass);
craftclass=id+" .c2";
cc(craftclass);
craftclass=id+" .c3";
cc(craftclass);
craftclass=id+" .output";
cc(craftclass);
}

function cc(cc)
{
var classitem=0;	
classitem=$(cc).html();
classitem=classitem||'0';


	$(cc).html("<img title='"+classitem+"' src='"+imgdir+classitem+".png' />");


}
function ul(dataurl)
{
	$("#up").html("<img src='data/img/loading.gif' />")
	$("#up").load("data/"+dataurl);
	
	
	};
function dl(dataurl)
{
	$("#down").html("<img src='data/img/loading.gif' />")
	$("#down").load("data/"+dataurl);

	};
function setC(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}	

function getC(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}	;
function sC(name,val)
{
	setC(name,val,7);
};

function setSave()
{
	font=document.getElementById('font').value;
	fonts=document.getElementById('fontsize').value;
	fontc=document.getElementById('fontcolor').value;
	tmd=document.getElementById('tmd').value;
	bgi=document.getElementById('bgi').value;
	sC('font',font);
	sC('fonts',fonts);
	sC('fontc',fontc);
	sC('tmd',tmd);
	sC('bgi',bgi);
	sC('seted',1);

};
function setload()
{var seted=0;
	seted=getC('seted')
	if(seted==1){
	document.getElementById('font').value=getC('font');
	document.getElementById('fontsize').value=getC('fonts');
	document.getElementById('fontcolor').value=getC('fontc');
	document.getElementById('tmd').value=getC('tmd');
	document.getElementById('bgi').value=getC('bgi');
	setapply()
	}
	else{}
}	;
	
function setapply()
{
setSave();
$("*").css('font-family',font);
$("*").css('font-size',fonts);
$("*").css('color',fontc);
$("#up,#down").css('opacity',tmd);
$("body").css('background-image','url('+bgi+')');

	}	;
	
function adjusthw()
{
	w1=$("#up").css('width');
w1=parseInt(w1);
w1-=30;
$('#up,#down').css('width',w1+'px');

h1=$('#down').css('height');
h1=parseInt(h1);
h1-=300;
$('#down').css('height',h1);
};	
	
//启动
function startup()
{
	
var w1=1024,h1=800;
$("#up,#down").css("width",'100%');
$("#down,#up").css("height",'100%');
setTimeout("adjusthw()",1100);


	setload();
	};
//开发工具箱代码	
function dev_copyc(id)
{$("#dev_testcraft ."+id).html($('#dev_'+id).val());
	};	
	
function dev_copy2(){
dev_copyc('a1');
dev_copyc('a2');
dev_copyc('a3');
dev_copyc('b1');
dev_copyc('b2');
dev_copyc('b3');
dev_copyc('c1');
dev_copyc('c2');
dev_copyc('c3');
dev_copyc('output');
$("#dev_codeout").html("id='"+$("#dev_output").val()+"'>"+$("#dev_testcraft").html()+"</ul>");
$("#dev_codeout").append("<");
$("#dev_codeout").append("script type='text/javascript'>craft('#"+$("#dev_output").val()+"');");
$("#dev_codeout").append("<");
$("#dev_codeout").append("/script>");
$("#dev_codeup").html("<li><img src='data/img/"+$("#dev_output").val()+".png' onclick=&quot;dl('"+$("#dev_output").val()+".html')&quot; /></li>")	;
switch ($('input[name="dev_ss"]:checked').val())
{
	case 'c':
	$("#dev_codeout").prepend("ul class='crafttable' ");
	break;
	case 's':
	$("#dev_codeout").prepend("ul class='smelting' ");
	break;
	case 'b':
	$("#dev_codeout").prepend("ul class='brewing' ");
	break;
	default	:;
	
	};



$("#dev_codeout").prepend("<");
};	
//工具箱种类设置
function dev_typeset()
{dback=$("#dev_a1,#dev_a2,#dev_a3,#dev_b1,#dev_b2,#dev_b3,#dev_c1,#dev_c2,#dev_c3").removeAttr('disabled');
	dev_ct=$('input[name="dev_ss"]:checked').val();
	
	switch(dev_ct){
	case 's':
	dback;
	$("#dev_a2,#dev_b1,#dev_b2,#dev_b3,#dev_c1,#dev_c2,#dev_c3").val('').attr('disabled','disabled');
	break;
	case 'b':
	dback;
	$("#dev_a2,#dev_a3,#dev_b2,#dev_b3,#dev_c2,#dev_c3").val('').attr('disabled','disabled');
	break;
	case 'c':
	dback;
	break;
	default	:;
};
		};	
	//主函数
function dev_start()
{dev_ct=$('input[name="dev_ss"]:checked').val();
switch(dev_ct){
case 'c':
dl('demo2.html');
break;
case 's':
dl('demo3.html');
break;
case 'b':
dl('demo4.html');
break;	
default	:;
};

setTimeout("dev_copy2()",20);
setTimeout("craft('#dev_testcraft')",30);

	}
	;	
function diy_craft(id)
{

$(id+" td:empty").css("visibility","hidden");	
$(id+" td").addClass("diytd");
$(id+" .diy_type").removeClass("diytd");
$(id+" .diy_output").removeClass("diytd");
$(id+" .diy_b").removeClass("diytd");
cc(id+" .diy_a");
cc(id+" .diy_b");
cc(id+" .diy_c");
cc(id+" .diy_type");
cc(id+" .diy_output");

	};	
function vcheck()
{
	$("input").each(function() 
	{
		var ihn=4;
	ih=$(this).val();
	ihn+=ih.indexOf('<');
	ihn+=ih.indexOf('(');
	ihn+=ih.indexOf("'");
	ihn+=ih.indexOf('&quot;');
	if(ih.indexOf('<')>=0){$(this).val('');alert('包含非法字符，引号括号是不能用的')}
	else{};
        
    });
	};	